package com.pengpeng.starter.config;

import com.pengpeng.starter.bean.PersonProperties;
import com.pengpeng.starter.service.PersonTemplate;
import com.pengpeng.starter.service.PersonWorker;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnJava;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.system.JavaVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(value = {PersonProperties.class})
@ConditionalOnClass(value = {PersonWorker.class})
public class PersonAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(value = {PersonTemplate.class})
    @ConditionalOnJava(JavaVersion.EIGHT)
    public PersonTemplate personTemplate(PersonProperties personProperties){
        PersonTemplate personTemplate = new PersonTemplate();
        personTemplate.setPersonProperties(personProperties);
        return personTemplate;
    }
}
